package com.hbue.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

//数据库工具类
public class DatabaseUtil {
    private static String driver = "com.mysql.jdbc.Driver";
    private static String url = "jdbc:mysql://localhost:3306/booksystem?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval";
    private static String username = "root";
    private static String password = "123456";
    //建立连接
    public static Connection getConnection() throws ClassNotFoundException, SQLException {
        //加载数据库驱动
        Class.forName(driver);
        //获取连接
        Connection connection = DriverManager.getConnection(url, username, password);
        return connection;
    }
}
